#pragma once 
#include"sock.hpp"
#include "channel.hpp"
class Listener : public Connection
{

public:
    Listener(uint32_t port) : _port(port), _listensock(make_unique<Tcpsocket>())
    {
        _listensock->arrangesock(_port);
     
        Setevents(EPOLLIN | EPOLLET);
        set_nonblock(GetSockFd());
        
    }
    //listen套接字只关心收事件
    void Recver()override{
        inetaddr client;
      while(1){
      int n=_listensock->Accept(&client);
  
      if(n==-1) break;//缓冲区读完了

      
      else if(n==-2) continue;//信号中断

      
      else if(n==-3) break; //发生意外

      
      else {
           shared_ptr<Connection>con=make_shared<Channel>(n,client);
            con->Setfunc(_func);
            Getowner()-> Addconnection(con);
      }
    }
    }
     void Sender()override{}
    void Excepter()override{}
     int GetSockFd() override{

        return _listensock->Fd();
     }
    ~Listener()
    {
    }

private:
    uint32_t _port;
    unique_ptr<Socket> _listensock;
};